package com.edais.actions;

import com.edais.service.advert.BannerManageService;
import com.yunzhi.domain.ResultConstant;
import com.yunzhi.domain.ResultDTO;
import com.yunzhi.util.RequestUtil;
import com.yunzhi.util.ResponseUtil;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/appInfo")
public class AppInfoAction {

    private static final Logger logger = Logger.getLogger(AppInfoAction.class);

    @Autowired
    private BannerManageService bannerManageService;

    /**
     * 获得APP启动页图片
     *
     * @Param response    请求响应
     */
    @RequestMapping(value = "/getStartPage")
    public void getStartPage(HttpServletRequest request, HttpServletResponse response) {
        try {
            if (!RequestUtil.validSign(request)) {
                logger.info("无效签名");
                ResponseUtil.write(response, ResultConstant.INVALID_SIGN);
                return;
            }
            ResultDTO resultDTO = this.bannerManageService.queryAppStartBanner();
            ResponseUtil.write(response, resultDTO);
        } catch (Exception e) {
            logger.error("appInfo/getStartPage 异常", e);
            ResponseUtil.write(response, ResultConstant.FAILED);
        }
    }
}
